<?php
namespace App\Dao\config;
use App\Dao\BaseDao;
use App\Models\config\ConfigModel;
use function Couchbase\defaultDecoder;
use Illuminate\Support\Facades\DB;
use App\Services\system\SystemLogServices;
use App\Exceptions\ApiException as HOException;
use Hlcreation\Basic\Helper;
class SmsDao extends BaseDao
{

    public function setModel(){
        return ConfigModel::class;
    }


    public function addSms($arr){

        DB::beginTransaction();
        try{

            $where = [
                'creator_uid'=>$arr['creator_uid'],
                'type'=>$arr['type'],
            ];

            ConfigModel::where($where)->forceDelete();

            /*$url = env('APP_CONTRACT_API_URL', 'http://192.168.1.199:84')."/adminapi/luming/login/saasStorage";
                  $arr_json= json_encode($arr);
                  $arr_encode=base64_encode($arr_json);
                  //dd($arr);
                  $res=Helper::httpPost($url,$arr_encode);*/
            //插入日志
            $LogServices = app()->make(SystemLogServices::class);
            $LogServices->SaveLog($arr['creator_uid'],'创建系统配置','配置项名称:'.'短信配置'.'--配置项ID:'.'18');

            ConfigModel::create([
                'menu_name'=>'status',
                'value'=>$arr['status'],
                'info'=>'短信配置',
                'desc'=>'短信配置',
                'status'=>1,
                'created_at'=>$arr['created_at'],
                'creator_uid'=>$arr['creator_uid'],
                'config_tab_id'=>18,
                'type'=>$arr['type'],
            ]);

            ConfigModel::create([
                'menu_name'=>'type',
                'value'=>4,
                'info'=>'短信配置',
                'desc'=>'短信配置',
                'status'=>1,
                'created_at'=>$arr['created_at'],
                'creator_uid'=>$arr['creator_uid'],
                'config_tab_id'=>18,
                'type'=>$arr['type'],
            ]);

            DB::commit();
            return true;
        }catch (\Exception $exception){
            DB::rollBack();
            throw new HOException($exception->getMessage());
        }

    }


    //查看短信配置
    public function  smsInfos($uid,$type){

        return  ConfigModel::where('type',$type)->where('creator_uid',$uid)->value('status');

    }











}
